#include "Color.h"

Color::Color() : r(0), g(0), b(0) {}

Color::Color(const int _r, const int _g, const int _b) : r(_r), g(_g), b(_b) {}

unsigned short int Color::red() const{
	if(r<0) return 0;
	else if(255<r) return 255;
	else return (unsigned short int)r;
}

unsigned short int Color::green() const{
	if(g<0) return 0;
	else if(255<g) return 255;
	else return (unsigned short int)g;
}

unsigned short int Color::blue() const{
	if(b<0) return 0;
	else if(255<b) return 255;
	else return (unsigned short int)b;
}

Color Color::operator + (const Color& c) const {

	int _r = r + c.r;
	int _g = g + c.g;
	int _b = b + c.b;

	return Color(_r,_g,_b);

}

void Color::operator += (const Color& c){
	r += c.r;
	g += c.g;
	b += c.b;
}

Color Color::operator - (const Color& c) const {

	int _r = r - c.r;
	int _g = g - c.g;
	int _b = b - c.b;

	return Color(_r,_g,_b);

}

void Color::operator -= (const Color& c){
	r -= c.r;
	g -= c.g;
	b -= c.b;
}

Color Color::operator * (const double& d) const {

	#ifdef DEBUG
		assert(d>=0);
	#endif

	double _r = r * d;
	double _g = g * d;
	double _b = b * d;

	return Color(_r,_g,_b);

}

void Color::operator *= (const double& d){

	#ifdef DEBUG
		assert(d>=0);
	#endif

	r *= d;
	g *= d;
	b *= d;
}

Color Color::operator / (const double& d) const {

	#ifdef DEBUG
		assert(d>=0);
	#endif

	double _r = (double)r / d;
	double _g = (double)g / d;
	double _b = (double)b / d;

	return Color(_r,_g,_b);

}

void Color::operator /= (const double& d){

	#ifdef DEBUG
		assert(d>=0);
	#endif

	r = (double)r / d;
	g = (double)g / d;
	b = (double)b / d;
}

ostream& operator << (ostream& os, const Color& c){
	os << '(' << c.red() << ',' << c.green() << ',' << c.blue() << ')';
}

